﻿using GrainManage.Proxy;

namespace GrainManage.Tools
{
    public sealed class StatusHelper
    {
        private const string cmdGet = "SELECT Message FROM StatusInfo WHERE StatusCode=?";

        public string GetMessage(int statusCode)
        {
            string message = GetLocalMessage(statusCode);
            if (string.IsNullOrEmpty(message))
            {
                message = GetServerMessage(statusCode);
            }
            return message;
        }

        public string GetLocalMessage(int statusCode)
        {
            var message = SQLite.ExecuteScalar(cmdGet, statusCode) as string;
            return message;
        }

        public string GetServerMessage(int statusCode)
        {
            var message = Creator.StatusProxy.GetMessage(statusCode);
            return message;
        }
    }
}
